package com.veetao.api.model;

import org.springframework.beans.factory.annotation.Autowired;

import com.veetao.api.resp.CommonResultResp;
import com.veetao.api.service.impl.I18nTipService;
import com.veetao.api.utils.NumberUtil;
/**
 * 
 * 
 * @author guohongtao
 * @date 2016年7月25日
 */
public abstract class ApiFacadeAdapter implements ApiFacade {
	
	
	@Autowired
	private I18nTipService tipSvc;
	public boolean isLoginUser(CommandContext context) {
		int userId = context.getUserId();
		return userId > 0;
	}

	public ApiFacadeAdapter() {
		super();
	}
	
	protected CommonResultResp getFailedResp(String labelName, CommandContext context) {
		return CommonResultResp.buildDefaultCodeFailResult(tipSvc.getTipMessage(labelName, context));
	}
	
	protected String getLocaleString(String labelName, CommandContext context) {
		return tipSvc.getTipMessage(labelName, context);
	}
			
	protected int getNumbericBuildNo(CommandContext context) {
		String buildNo = context.getBuildNo();
		if(buildNo == null) {
			return 0;
		}
		buildNo = buildNo.replaceAll("\\D", "");
		if(NumberUtil.isNumber(buildNo)) {
			return Integer.parseInt(buildNo);
		}
		
		return 0;
		
		
	}

	public I18nTipService getTipSvc() {
		return tipSvc;
	}

	public void setTipSvc(I18nTipService tipSvc) {
		this.tipSvc = tipSvc;
	}

}
